Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PSR-2 Compliance] Fix #8612: Hundreds of PHPCS-based static tests violations in mainline #8685

Merged
merged 6 commits into from
Mar 15, 2017

Conversation

orlangur
Copy link
Contributor

@orlangur orlangur commented Feb 26, 2017

Scope of Work

  • Enabled PHPCS-based tests for the whole codebase
  • Combined three PHPCS-based tests into one
  • Polished up Magento Coding Standard into one ruleset.xml
    • no new rules added
    • only those rules were removed which are contained in PSR2
  • Made static tests run under PHP 7 which is ~3 times faster than PHP 5.6
  • Fixed all existing coding style violations, mostly using automation tools
    • no @codingStandardsIgnoreFile annotations removed to reduce size of PR
    • new @codingStandardsIgnoreFile only added when really necessary:
      • one wrongly named interface marked with @api (can be addressed separately, didn't want to mix with cosmetic changes)
      • few phtml files which show false-positive with currently used PHPCS 1.5.3 and no violation with latest stable PHPCS 2.8.0 (example: orlangur@ecf0948)

Code Review Notes

@okorshenko okorshenko self-assigned this Feb 27, 2017
@okorshenko okorshenko added this to the February 2017 milestone Feb 27, 2017
@okorshenko
Copy link
Contributor

@orlangur thank you for this contribution. It will take some time to review all changes in this PR. And thank you for providing URL for the code change which requires manual review

@okorshenko okorshenko self-requested a review February 27, 2017 03:51
@okorshenko
Copy link
Contributor

okorshenko commented Feb 27, 2017

Made static tests run under PHP 7 which is ~3 times faster than PHP 5.6

+100500 to your karma! 👍

@PieterCappelle
Copy link
Contributor

Would clean up the code. Very nice PR.

@maksek maksek modified the milestones: February 2017, March 2017 Mar 1, 2017
@okorshenko okorshenko added this to the March 2017 milestone Mar 1, 2017
@orlangur
Copy link
Contributor Author

orlangur commented Mar 3, 2017

@okorshenko, please ping me back if I need to resolve merge conflicts in order to get this merged.

Currently there is only one pretty easy to fix conflict in app/code/Magento/Analytics/ReportXml/ReportProvider.php, as I did not change semantics of this piece of code, just formatting.

@okorshenko
Copy link
Contributor

Hi @orlangur
Could you please provide step by step instruction how to reproduce your fix. So that we will review only manual changes and automatically verify auto changes.

Please, resolve the conflicts if you can. Thank you

@orlangur
Copy link
Contributor Author

@okorshenko, in PR description I mentioned

Commits orlangur/magento2@74f3a5a and orlangur/magento2@bc79f6d are obtained using automatic tools, step-by-step instructions are present in commit messages; to review them simply repeat the same steps and assure that no changes shown by git diff

There you can see:

  • Step 0. Install php-cs-fixer globally: composer global require friendsofphp/php-cs-fixer:2.1.0
  • Step 1. Remove outdated php-cs-fixer config: rm .php_cs
    ...

for both of automatic commits :)

The last small commit 9db86d8 is manual too, it is not possible to squash with changes before automatic commits as those changes are in files with CRLF line breaks.

Ok, will resolve conflicts by hard reset before automatic commits + re-apply of automatic changes. So, don't be surprised there will be no merge commit (of course, if there are no conflicting changes with my manual changes in mainline).

…ests violations in mainline

- enable PHPCS-based tests for the whole codebase
- combine three PHPCS-based tests into one
- polish up Magento Coding Standard into one ruleset.xml: no new rules added, only those rules removed which are already contained in PSR2
- run static tests under PHP 7 which is ~3 times faster than PHP 5.6
…ests violations in mainline

- apply manual fixes to make PHPCS happy, changes for "Constants are not allowed as the first argument of translation function, use string literal instead"
- third-party constants are simply ignored, not sure if this is correct or not
…ests violations in mainline

- apply manual fixes to make PHPCS and PHPMD happy
- some phtml templates marked as ignored for now as PHPCS 1.5.3 version produces false-positives on them (PHPCS 2.8.0 treats them fine)
…ests violations in mainline

- apply automatic PHP-CS-FIXER fixes to make PHPCS happy
- Step 0. Install php-cs-fixer globally: composer global require friendsofphp/php-cs-fixer:2.1.0
- Step 1. Remove outdated php-cs-fixer config: rm .php_cs
- Step 2. Execute tool: ~/.composer/vendor/friendsofphp/php-cs-fixer/php-cs-fixer fix . --rules=no_extra_consecutive_blank_lines,method_separation -v
- Step 3. Reset changed fixture file to not break related unit test: git checkout HEAD -- lib/internal/Magento/Framework/Code/Test/Unit/_files/app/code/Magento/SomeModule/Model/SevenInterface.php
- Step 4. Restore outdated php-cs-fixer config: git checkout HEAD -- .php_cs
…ests violations in mainline

- apply automatic PHPCBF fixes to make PHPCS happy
- Step 0. Install phpcs globally: composer global require squizlabs/php_codesniffer:2.8.0
- Step 1. Execute tool to fix PSR-2 violations in PHP files: ~/.composer/vendor/squizlabs/php_codesniffer/scripts/phpcbf --standard=PSR2 --extensions=php --ignore=generated/*,vendor/*,var/* .
…ests violations in mainline

- apply manual fixes to make PHPCS and PHPMD happy
@orlangur orlangur force-pushed the phpcs-tests-refactoring branch from 9db86d8 to f122079 Compare March 11, 2017 13:34
@orlangur
Copy link
Contributor Author

Rebased against latest mainline and reapplied fixes.

Manual commits: 0338636, c3e7df5, 8d379e6, f122079

Automated commits: 749518c, 002d771

Old branch (for the reference): https://github.com/magento/magento2/compare/develop...orlangur:phpcs-tests-refactoring-before-sync?expand=1

@okorshenko
Copy link
Contributor

@orlangur thank you

@okorshenko
Copy link
Contributor

okorshenko commented Mar 14, 2017

@orlangur from the first look everything is ok.
There are 2 logical errors in /pub/errors/processor.php

!is_null($local) ==> $local === null

I will fix it on our side

Tomorrow I will code review one more time to make sure I didn't miss any other issues. After that, I will start merge procedure.

Thank you for this PR!

@orlangur
Copy link
Contributor Author

!is_null($local) ==> $local === null

Oh, my bad, sorry, it would be better to fix it with php-cs-fixer too, just didn't bother to.

@okorshenko
Copy link
Contributor

okorshenko commented Mar 14, 2017

@orlangur could you please provide detailed explanation why some rules were removed from the ruleset:

  • Zend.Files.ClosingTag
  • Zend.NamingConventions.ValidVariableName (explude PrivateNoUnderscore)
  • PEAR.NamingConventions.ValidClassName
  • PEAR.Classes.ClassDeclaration
  • PEAR.Functions.FunctionDeclaration
  • PEAR.WhiteSpace.ScopeClosingBrace
  • PEAR.ControlStructures.ControlSignature

Please let me know if I missed some other rules

@orlangur
Copy link
Contributor Author

@okorshenko explanation is already provided in 0338636 commit message:

  • polish up Magento Coding Standard into one ruleset.xml: no new rules added, only those rules removed which are already contained in PSR2

@magento-team magento-team merged commit f122079 into magento:develop Mar 15, 2017
@okorshenko
Copy link
Contributor

@orlangur thank you for your contribution. Your Pull Request has been successfully merged. Great job!

@fooman
Copy link
Contributor

fooman commented Mar 15, 2017

Awesome stuff @orlangur

@orlangur
Copy link
Contributor Author

Cool, thx! :)

Didn't expect it to be merged that fast (or even merged at all :D). Magento 2 contribution starting to be a pleasure, keep up the decent pace reached 👍

@orlangur orlangur deleted the phpcs-tests-refactoring branch March 15, 2017 23:50
@PieterCappelle
Copy link
Contributor

Great to see that this commit has been merged so quickly. Keep up this fantastic progress!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants